from flask import Flask,make_response,url_for,request

app = Flask(__name__)

# 参数 http://127.0.0.1:5000/100
@app.route("/") # 默认配置
@app.route("/<int:age>") # 如果没有默认配置不写100则为404
def hello_world(age = None):
	return "hello world first flask app, you age is %s" % age

# HTTP方法限定
@app.route("/login", methods = ["POST"])
def dologin():
	return "dologin";


@app.route("/test_after_req")
def test_after_req():

	@app.after_request
	def set_cookie(response):
		print("set_cookie", flush = True)
		return response

	return "test_after_req";


@app.route("/show_url_for")
def show_url_for():
	try:
		str1 = request.form["username"]
	except Exception as e:
		print(e)
	return url_for("dologin")
	

@app.after_request
def my_after_request(response):
	print("my after request", flush = True)
	return response


if __name__ == "__main__":
	# app.debug = True
	app.run()